<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="" />
  </head>
  <body>
    <div style="width: 70%; position: absolute; left: 100px; top: 100px">
      <div style="margin: 50px; background-color: yellow">
        <p>点击下面的按钮可以设置本段落的最近的父（祖先）元素的背景色。</p>
        <div></div>
        <button>点击这里</button>
      </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
    <script>
      $(document).ready(function () {
        $('button').click(function () {
          $('p').offsetParent().css('background-color', 'red')
        })
      })
    </script>
  </body>
</html>
